'''
1、尝试使用telnet登录设备，并输出其接口摘要信息，并将输出结果翻译成人话；
2、自动把管理down的接口开；
3、自动再把down down 的接口管理down了；
'''

import telnetlib
import time


DeviceInfoList = [
('203.0.113.1','admin','admin','sw1'),
# ('10.1.100.252','qytang','qytang','sw1'),
# ('10.1.100.253','qytang','qytang','sw2'),
# ('10.1.100.103','qytang','qytang','sw3'),
# ('10.2.100.103','qytang','qytang','sw4'),
]


for a,b,c,d in DeviceInfoList:
	TN = telnetlib.Telnet(a)
	TN.read_until(b'Username:')
	TN.write(b.encode('ascii')+b'\n')
	TN.read_until(b'Password:')
	TN.write(c.encode('ascii')+b'\n')
	Hostname = d+'#'
	Hostname = bytes(Hostname,encoding = 'utf-8')
	TN.read_until(Hostname).decode('ascii')

	TN.write('terminal length 0'.encode('ascii')+b'\n')
	TN.read_until(Hostname)
	TN.write('show running'.encode('ascii')+b'\n')
	Config = TN.read_until(Hostname).decode('ascii')
	print(Config)

TN.close()

